/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package acteur.gestionnaires;

import acteur.modeles.Acteur;
import java.util.Collection;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author hlaffineur
 */
@Stateless
@LocalBean
public class GestionnaireActeur {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @PersistenceContext  
    private EntityManager em;
    
    public Acteur creerAct(String lastname, String firstname, String datebirth, String descr){
        Acteur a = new Acteur(lastname,firstname,datebirth,descr);
        em.persist(a);
        return a;
    }
    
    public void peupleLaBaseActAvecJeuDeTest(){
        creerAct("Reeves", "Keanu", "1964", "Lebanese, also producer");
        creerAct("Fishburne", "Laurence", "1961", "American, also producer and scenarist");
        creerAct("Moss", "Carrie-Anne", "1967", "Canadian");
        creerAct("Hamill", "Mark", "1951", "American, also producer and scenarist");
        creerAct("Ford", "Harrison", "1942", "American, won 2 Awards and a Cesar");
        creerAct("Fisher", "Carrie", "1956", "American");
        creerAct("Worthington", "Sam", "1976", "English");
        creerAct("Saldana", "Zoe", "1978", "American");
        creerAct("Weaver", "Sigourney", "1949", "American");
        creerAct("Neeson", "Liam", "1952", "Irish");
        creerAct("McGregor", "Ewan", "1971", "Scotish");
        creerAct("Portman", "Natalie", "1981", "Israelian, won 8 prices");
        creerAct("Christensen", "Hayden", "1981", "Canadian");
        creerAct("Tatum", "Channing", "1980", "American");
        creerAct("Dewan", "Jenna", "1980", "American");
        creerAct("Radcliff", "Damaine", "1979", "American");
        creerAct("Featherston", "Katie", "1982", "American");
        creerAct("Sloat", "Micah", "1980", "American");
        creerAct("Smith", "Will", "1968", "American");
        creerAct("Lee Jones", "Tommy", "1946", "American");
        creerAct("Leary", "Denis", "1957", "American");
        creerAct("Romano", "Ray", "1957", "American");
        creerAct("Leguizamo", "John", "1964", "Colombian");
        creerAct("Myers", "Mike", "1963", "Canadian");
        creerAct("Murphy", "Eddie", "1961", "American");
        creerAct("Diaz", "Cameron", "1972", "American");
        creerAct("Berryman", "Michael", "1948", "American");
        creerAct("Nicholson", "Jack", "1937", "American");
        creerAct("Redford", "Robert", "1936", "American");
        creerAct("Scott Thomas", "Kristin", "1960", "English");
        creerAct("Johansson", "Scarlett", "1984", "American");
        creerAct("Hanks", "Tom", "1956", "American");
        creerAct("Morse", "David", "1953", "American");
        creerAct("Willis", "Bruce", "1955", "American");
        creerAct("Affleck", "Ben", "1972", "American");
        creerAct("Tyler", "Liv", "1977", "American");
        creerAct("Jovovich", "Milla", "1975", "Ukrainian");
        creerAct("Pitt", "Brad", "1963", "American");
        creerAct("Bloom", "Orlando", "1977", "English");
        creerAct("Kruger", "Diane", "1976", "German");
        creerAct("Hartnett", "Josh", "1978", "English");
        creerAct("Beckinsale", "Kate", "1973", "English");
    }
    
    public Collection<Acteur> getAllActeur() {
        Query q = em.createQuery("select a from Acteur a");
        return q.getResultList();
    }
    
    public Acteur getActeur(String nom, String prenom) {
        Query q = em.createQuery("select a from Acteur a where a.nom ='" + nom + "' and a.prenom = '" + prenom + "'");
        return (Acteur)q.getSingleResult();
    }
}
